//
//  EventGroupListViewController.m
//  League
//
//  Created by 崔璨 on 2018/1/26.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "EventGroupListViewController.h"
#define kCellHeight 90
#define kTitleFontSize 15
@interface EventGroupListViewController ()<UITableViewDelegate , UITableViewDataSource>
{
    
}
@property(strong , nonatomic)UITableView *tableV;
@end

@implementation EventGroupListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.titleStr;
    if (@available(iOS 11.0, *)) {
        self.tableV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self TableView];
    
}
-(void)TableView
{
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height-64)];//指定位置大小
    self.tableV.backgroundColor = [UIColor clearColor];
    [self.tableV setDelegate:self];//指定委托
    [self.tableV setDataSource:self];//指定数据委托
    self.tableV.estimatedRowHeight = 0;
    self.tableV.estimatedSectionHeaderHeight = 0;
    self.tableV.estimatedSectionFooterHeight = 0;
    self.tableV.layer.masksToBounds = YES;
    self.tableV.layer.cornerRadius = 10;
//    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableV];//加载tableview
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  12;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
    //    if (!cell) {
    //        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableViewCell"];
    //
    //    }
    static NSString *CellIdentifier = @"TableViewCell";
    // 通过indexPath创建cell实例 每一个cell都是单独的
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 10;
        cell.width = tableView.width;
        cell.height = kCellHeight;
    }
    NSInteger space = 10;
    UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.height*0.8, cell.height*0.8)];
    headImage.center = CGPointMake(space+headImage.width/2, cell.height/2);
    headImage.backgroundColor = [UIColor redColor];
    headImage.layer.masksToBounds = YES;
    headImage.layer.cornerRadius = headImage.height/2;
    [cell addSubview:headImage];
    [headImage sd_setImageWithURL:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1516968522648&di=24ed28db1e3791cfdc8977775be0fe35&imgtype=0&src=http%3A%2F%2Fp1.qqyou.com%2Ftouxiang%2FUploadPic%2F2015-4%2F15%2F201504151133475846.jpg"];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(headImage.x+headImage.width+space, 0, cell.width - headImage.width-space*2, cell.height)];
    titleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    [cell addSubview:titleLab];
    titleLab.text = @"Introducing League Events";
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"row:%@ - section:%@",@(indexPath.row) , @(indexPath.section));
}
    
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kCellHeight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
